package br.com.duduso.conferencia_claro_desktop.jasderdatasource;

import br.com.duduso.conferencia_claro_desktop.entity.Detalhe;
import java.util.Iterator;
import java.util.List;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

/**
 *
 * @author duduso
 */
public class DetalheJRDataSource implements JRDataSource{

    private Iterator<Detalhe> iterator;

    private Detalhe cursor;

    public DetalheJRDataSource(List<Detalhe> detalhes) {
            super();
            iterator = detalhes.iterator();
    }

    @Override
    public boolean next() throws JRException {
            boolean retorno = iterator.hasNext();
            if(retorno){
                    cursor = iterator.next();
            }
            return retorno;
    }

    @Override
    public Object getFieldValue(JRField nameField) throws JRException {
            Detalhe detalhe = cursor;
            if(isEqualsNameField(nameField, "cliente")){
                    return detalhe.getCliente();
            }
            if(isEqualsNameField(nameField, "dataLigacao")){
                    return detalhe.getDataLigacao();
            }
            if(isEqualsNameField(nameField, "descricao")){
                    System.out.println("Descrição Encontrada = " + detalhe.getDescricao());
                    return detalhe.getDescricao();
            }
            if(isEqualsNameField(nameField, "duracao")){
                    return detalhe.getDuracaoLigacao();
            }
            if(isEqualsNameField(nameField, "hora")){
                    return detalhe.getHora();
            }
            if(isEqualsNameField(nameField, "numeroDiscado")){
                    return detalhe.getNumeroDiscado();
            }
            if(isEqualsNameField(nameField, "origemDestino")){
                    return detalhe.getOrigemDestino();
            }
            if(isEqualsNameField(nameField, "tarifa")){
                    return detalhe.getTarifa();
            }
            if(isEqualsNameField(nameField, "telefone")){
                    return detalhe.getTelefone();
            }
            if(isEqualsNameField(nameField, "valorLigacao")){
                    return detalhe.getValorLigacao();
            }
            return null;
    }

    private boolean isEqualsNameField(JRField nameField, String value){
            return nameField.getName().equals(value);
    }

}
